import { Controller } from "../../mvc/core/Controller";
import { ISuperTeamBuyDayModule } from "../../../modules/interfaces/ISuperTeamBuyDayModule";
import { SuperTeamBuyDayModule } from "../../../modules/SuperTeamBuyDayModule";
import { SuperTeamBuyIcon } from "../view/superTeamBuy/SuperTeamBuyIcon";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SSpecialPanicBuyWishCardCanGet } from "../../../Message/Game/SSpecialPanicBuyWishCardCanGet";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { SSpecialPanicBuyItemInfo } from "../../../Message/Game/SSpecialPanicBuyItemInfo";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
//class SuperTeamBuyDayController
    
    export  class SuperTeamBuyDayController extends Controller
    {
       

        public get module(): ISuperTeamBuyDayModule
        {
            if (!this._module) 
            {
                this._module = new SuperTeamBuyDayModule();
            }
            return this._module;
        }

        public get icon(): SuperTeamBuyIcon
        {
            if (!this._icon) 
            {
                this._icon = new SuperTeamBuyIcon();
                this._icon.updateIconInfo();
            }
            return this._icon;
        }

        protected /* override */ initServer(): void
        {
            Dispatcher.addEventListener(EventName.OnGetTicketClick, this.onGetTicket);
            Dispatcher.addEventListener(EventName.onClickActiveIcon, this.openView);
            Dispatcher.addEventListener(EventName.OnBuyOrSaleClick, this.onBuyOrSaleHandler);
            NetDispatcher.addCmdListener(ServerCommand.SuperTeamBuyDaysInfo, this.onActiveIsOpen);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicSpecialPanicBuyItemInfo, this.onActiveInfo);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicSpecialPanicBuyCanGetWishCard, this.isWishCardCanGet);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onPackChangeHandler);
            return;
        }

        /* internal  */onPackChangeHandler(arg1: Object): void
        {
            if (!this.module.isHide) 
            {
                this.module.onChangeInPack();
            }
            return;
        }

        /* internal  */isWishCardCanGet(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSpecialPanicBuyWishCardCanGet;
            if (!this.module.isHide) 
            {
                if (loc1.canGet > 0) 
                {
                    this.module.setHighLightBtn(true);
                }
                else 
                {
                    this.module.setHighLightBtn(false);
                }
            }
            return;
        }

        /* internal  */onBuyOrSaleHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data;
            var loc2=loc1.type;
            var loc3=loc1.code;
            var loc4=loc1.amount;
            GameProxy.active.buyOrSale(loc2, loc3, loc4);
            return;
        }

        /* internal  */onActiveInfo(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SSpecialPanicBuyItemInfo;
            if (!this.module.isHide) 
            {
                this.module.updateItem(loc1);
            }
            return;
        }

        /* internal  */openView(arg1: DataEvent): void
        {
            if (this.module.isHide) 
            {
                this.module.show();
                this.module.actTime = this._time;
                GameProxy.active.getSuperTeamBuyDayInfo();
            }
            else 
            {
                this.module.hide();
            }
            return;
        }

        /* internal  */onActiveIsOpen(arg1: SActiveToClient): void
        {
            if (arg1.status) 
            {
                this.icon.show();
                this.setTime(arg1.startDt, arg1.endDt);
            }
            else 
            {
                this.icon.hide();
            }
            return;
        }

        /* internal  */onGetTicket(arg1: DataEvent): void
        {
            GameProxy.active.getWishCard();
            return;
        }

        /* internal  */setTime(arg1: Date, arg2: Date): void
        {
            this._time = arg1.month + 1 + "." + arg1.date + " - " + (arg2.month + 1) + "." + arg2.date;
            return;
        }

        private /* var */_module: ISuperTeamBuyDayModule;

        private /* var */_icon: SuperTeamBuyIcon;

        private /* var */_time: string;
    }
